package ch5;
import java.util.Scanner;

public class Ex1 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        isPrime(n,10);
    }
    public static void isPrime(int n, int line) {
        int count = 0; // Count the number of prime numbers
        int number = 2; // A number to be tested for primeness
        // Repeatedly find prime numbers
        while (count < n) {
            // Assume the number is prime
            boolean isPrime = true; // Is the current number prime?

            // Test if number is prime
            for (int divisor = 2; divisor <= number / 2; divisor++) {
                if (number % divisor == 0) { // If true, number is not prime
                    isPrime = false; // Set isPrime to false
                    break; // Exit the for loop
                }
            }

            // Test if number is palindrome
            boolean isPalindrome = true;
            String strNumber = number+"";
            int low = 0;
            int high = strNumber.length() - 1;
            while (low < high) {
                if (strNumber.charAt(low) != strNumber.charAt(high)) {
                    isPalindrome = false;
                    break;
                }
                low++;
                high--;
            }

            // Print the prime number and increase the count
            if (isPrime && isPalindrome) {
                count++; // Increase the count
                System.out.print(number + " ");
                if (count % line == 0 && count != n) {
                    // Print the number and advance to the new line
                    System.out.println();
                }

            }

            // Check if the next number is prime
            number++;
        }
    }
}